﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DimMock.Tests
{
    /// <summary>
    /// Summary description for CustomTypes
    /// </summary>
    [TestClass]
    public class CustomTypes
    {
        public CustomTypes()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        #region Simple Type
        protected class MockType1
        {
            public String Name { get; set; }
            public Guid ID { get; set; }
            public int Count { get; set; }
        }

        private void Verify(MockType1 mock)
        {
            Assert.IsNotNull(mock);
            Assert.IsFalse(String.IsNullOrEmpty(mock.Name));
            Assert.IsNotNull(mock.ID);
            Assert.AreNotEqual(Guid.Empty, mock.ID);
            Assert.AreNotEqual(0, mock.Count);
        }

        [TestMethod]
        public void SimpleCustomTypeTest()
        {
            var mock = Mock.Create<MockType1>();
            Verify(mock);
        }

        [TestMethod]
        public void SimpleCustomTypeListTest()
        {
            var mock = Mock.Create<MockType1>(10, 30);
            foreach (var m in mock)
                Verify(m);
        }
        #endregion

        #region Nested Simple Type
        protected class MockType2
        {
            public Guid ID { get; set; }
            public String Name { get; set; }
            public MockType1 Child { get; set; }
        }

        private void Verify(MockType2 mock)
        {
            Assert.IsNotNull(mock);
            Assert.IsFalse(String.IsNullOrEmpty(mock.Name));
            Assert.IsNotNull(mock.ID);
            Verify(mock.Child);
        }

        [TestMethod]
        public void NestedCustomTypeTest()
        {
            var mock = Mock.Create<MockType2>();
            Verify(mock);
        }

        [TestMethod]
        public void NestedCustomTypeListTest()
        {
            var mock = Mock.Create<MockType2>(20, 30);
            foreach(var m in mock)
                Verify(m);
        }
        #endregion

        protected class MockType3
        {
            public Guid ID { get; set; }
            public String Name { get; set; }
            public List<MockType1> Child { get; set; }
        }

        private void Verify(MockType3 mock)
        {
            Assert.IsNotNull(mock);
            Assert.IsFalse(String.IsNullOrEmpty(mock.Name));
            Assert.IsNotNull(mock.ID);
            Assert.IsNotNull(mock.Child);
            foreach(var m  in mock.Child)
                Verify(m);
        }

        //[TestMethod] disabled; working on it
        public void NestedCustomeTypeNestedListTest()
        {
            var mock = Mock.Create<MockType3>();
            Verify(mock);
        }
    }
}
